package com.sushi.service.impl;

import com.sushi.dao.PersonDao;
import com.sushi.pojo.Person;
import com.sushi.service.LogService;
import com.sushi.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PersonServiceImpl implements PersonService {

    @Autowired
    @Qualifier("personDao")
    private PersonDao personDao;
    @Autowired
    private LogService logService;


    @Override
    public void m1() {
        System.out.println("111111111");
    }

    @Override
    public List<Person> findAll() {
        return personDao.findAll();
    }

    @Override
    public Person findById(int id) {
        return personDao.findById(id);
    }

    @Override
    public List<Person> findByName(String name) {
        return personDao.findByName(name);
    }

//    @Override
//    public void update(Person person) {
//        personDao.update(person);
//    }

    @Override
    public void deleteById(int id) {
        personDao.deleteById(id);
    }

    @Override
    public void change(String name1, String name2, int num) {
        try {
            personDao.outAge(name1, num);
            int i = 1 / 0;
            personDao.inAge(name2, num);
        } finally {
            logService.log(name1, name2, num);
        }
    }


//    @Override
//    public void insert(Person person) {
//        personDao.insert(person);
//    }
}
